package com.handyshop.mall.user.controller;

import com.handyshop.mall.basic.core.vo.ResultVo;
import com.handyshop.mall.dubbo.user.entity.SysRole;
import com.handyshop.mall.user.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hs
 * @date 2020/11/30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysRole")
@Api(tags = "角色管理模块")
public class SysRoleController {

    private final SysRoleService sysRoleService;

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询角色信息")
    public ResultVo<SysRole> getById(@PathVariable Long id) {
        return ResultVo.success(sysRoleService.getById(id));
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加角色")
    //@PreAuthorize("@pms.hasPermission('sys_role_add')")
    public ResultVo<Boolean> save(@Validated @RequestBody SysRole sysRole) {
        return ResultVo.success(sysRoleService.save(sysRole));
    }

    @PutMapping("/edit")
    @ApiOperation(value = "修改角色")
    //@PreAuthorize("@pms.hasPermission('sys_role_edit')")
    public ResultVo<Boolean> update(@Validated @RequestBody SysRole sysRole) {
        return ResultVo.success(sysRoleService.updateById(sysRole));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除角色")
    //@PreAuthorize("@pms.hasPermission('sys_role_del')")
    public ResultVo<Boolean> removeById(@PathVariable Long id) {
        return ResultVo.success(sysRoleService.removeById(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取角色列表")
    public ResultVo<List<SysRole>> list() {
        return ResultVo.success(sysRoleService.list());
    }

}
